﻿Imports Comunes
Imports Microsoft.VisualBasic

Public Class UtilidadesPaginas
    ''' <summary>
    ''' Envia un Alert con el parametro entregado
    ''' </summary>
    ''' <param name="strmensaje">Mensaje a desplegar en el Alert</param>
    ''' <param name="asp">Pagina de referencia</param>
    ''' <remarks></remarks>
    Public Shared Sub mensaje(ByVal strmensaje As String, ByVal asp As Page)
        Dim winAlert As String = "alert('" & strmensaje & "');"
        System.Web.UI.ScriptManager.RegisterStartupScript(asp, asp.GetType(), "click", winAlert, True)
    End Sub

    ''' <summary>
    ''' Registra un Script para su ejecución en la página
    ''' </summary>
    ''' <param name="Script">Script a Ejecutar</param>
    ''' <param name="asp">Página donde se Ejecutara</param>
    ''' <remarks></remarks>
    Public Shared Sub EjecutaScript(ByVal Script As String, ByVal asp As Page)
        System.Web.UI.ScriptManager.RegisterStartupScript(asp, asp.GetType(), "click", Script, True)
        'System.Web.UI.ScriptManager.RegisterClientScriptBlock(asp, asp.GetType(), "click", Script, True)
    End Sub

    ''' <summary>
    ''' Ejecuta un Confirm en JavaScript el cual devuelve el metodo a ejecutar y  true o false segun la respuesta dada (Lo Envia por PostBack)
    ''' </summary>
    ''' <param name="msg">Mensaje para el Confirm</param>
    ''' <param name="metodo">Parametro para rescatar desde el Load (Lo envia por DoPostBack)</param>
    ''' <param name="asp">Pagina donde se Ejecutara el Confirm</param>
    ''' <remarks></remarks>
    Public Shared Sub ShowMessageConfirm(ByVal msg As String, ByVal metodo As String, ByVal asp As Page)
        Dim winAlert As String = "if(confirm('" & msg & "')) { " & "__doPostBack('" & metodo & "','true'); " & " } else{__doPostBack('" & metodo & "','false'); }"
        System.Web.UI.ScriptManager.RegisterStartupScript(asp, asp.GetType(), "click", winAlert, True)
    End Sub

    ''' <summary>
    ''' Reemplaza Los caractéres conflictivos dentro de una cadena
    ''' </summary>
    ''' <param name="inputline">Linea a Reemplazar los caracteres</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function replace(ByVal inputline As String) As String
        inputline = inputline.Replace("ñ", "n")
        inputline = inputline.Replace("Ñ", "N")
        inputline = inputline.Replace("á", "a")
        inputline = inputline.Replace("é", "e")
        inputline = inputline.Replace("í", "i")
        inputline = inputline.Replace("ó", "o")
        inputline = inputline.Replace("ú", "u")
        inputline = inputline.Replace("Á", "A")
        inputline = inputline.Replace("É", "E")
        inputline = inputline.Replace("Í", "I")
        inputline = inputline.Replace("Ó", "O")
        inputline = inputline.Replace("Ú", "U")
        inputline = inputline.Replace("Ä", "A")
        inputline = inputline.Replace("Ë", "E")
        inputline = inputline.Replace("Ï", "I")
        inputline = inputline.Replace("Ö", "O")
        inputline = inputline.Replace("Ü", "U")
        inputline = inputline.Replace("ä", "a")
        inputline = inputline.Replace("ë", "e")
        inputline = inputline.Replace("ï", "i")
        inputline = inputline.Replace("ö", "o")
        inputline = inputline.Replace("ü", "u")
        inputline = inputline.Replace("à", "a")
        inputline = inputline.Replace("è", "e")
        inputline = inputline.Replace("ì", "i")
        inputline = inputline.Replace("ò", "o")
        inputline = inputline.Replace("ù", "u")
        inputline = inputline.Replace("À", "A")
        inputline = inputline.Replace("È", "E")
        inputline = inputline.Replace("Ì", "I")
        inputline = inputline.Replace("Ò", "O")
        inputline = inputline.Replace("Ù", "U")
        inputline = inputline.Replace("â", "a")
        inputline = inputline.Replace("ê", "e")
        inputline = inputline.Replace("î", "i")
        inputline = inputline.Replace("ô", "o")
        inputline = inputline.Replace("û", "u")
        inputline = inputline.Replace("Â", "A")
        inputline = inputline.Replace("Ê", "E")
        inputline = inputline.Replace("Î", "I")
        inputline = inputline.Replace("Ô", "O")
        inputline = inputline.Replace("Û", "U")
        inputline = inputline.Replace("Ã", "A")
        inputline = inputline.Replace("ã", "a")
        inputline = inputline.Replace("õ", "o")
        inputline = inputline.Replace("Õ", "O")
        inputline = inputline.Replace("å", "a")
        inputline = inputline.Replace("Å", "A")
        inputline = inputline.Replace("<", " ")
        inputline = inputline.Replace(">", " ")
        inputline = inputline.Replace(":", " ")
        inputline = inputline.Replace("&", " ")
        inputline = inputline.Replace(".", " ")
        inputline = inputline.Replace("]", " ")
        inputline = inputline.Replace("!", " ")
        inputline = inputline.Replace("#", " ")
        inputline = inputline.Replace("$", " ")
        inputline = inputline.Replace("%", " ")
        inputline = inputline.Replace("'", " ")
        inputline = inputline.Replace("(", " ")
        inputline = inputline.Replace(")", " ")
        inputline = inputline.Replace("+", " ")
        inputline = inputline.Replace("´", " ")
        inputline = inputline.Replace("-<", " ")
        inputline = inputline.Replace("/", " ")
        inputline = inputline.Replace(";", " ")
        inputline = inputline.Replace("?", " ")
        inputline = inputline.Replace("@", " ")
        inputline = inputline.Replace("\", " ")
        inputline = inputline.Replace("^", " ")
        inputline = inputline.Replace("_", " ")
        inputline = inputline.Replace("`", " ")
        inputline = inputline.Replace("{", " ")
        inputline = inputline.Replace("}", " ")
        inputline = inputline.Replace("|", " ")
        inputline = inputline.Replace("~", " ")
        inputline = inputline.Replace("¡", " ")
        inputline = inputline.Replace("¢", " ")
        inputline = inputline.Replace("£", " ")
        inputline = inputline.Replace("¤", " ")
        inputline = inputline.Replace("¥", " ")
        inputline = inputline.Replace("", " ")
        inputline = inputline.Replace("¦", " ")
        inputline = inputline.Replace("§", " ")
        inputline = inputline.Replace("¨", " ")
        inputline = inputline.Replace("©", " ")
        inputline = inputline.Replace("ª", " ")
        inputline = inputline.Replace("«", " ")
        inputline = inputline.Replace("¬", " ")
        inputline = inputline.Replace("®", " ")
        inputline = inputline.Replace("¯", " ")
        inputline = inputline.Replace("°", " ")
        inputline = inputline.Replace("±", " ")
        inputline = inputline.Replace("²", " ")
        inputline = inputline.Replace("³", " ")
        inputline = inputline.Replace("´", " ")
        inputline = inputline.Replace("µ", " ")
        inputline = inputline.Replace("¶", " ")
        inputline = inputline.Replace("·", " ")
        inputline = inputline.Replace("¸", " ")
        inputline = inputline.Replace("¹", " ")
        inputline = inputline.Replace("º", " ")
        inputline = inputline.Replace("»", " ")
        inputline = inputline.Replace("¼", " ")
        inputline = inputline.Replace("½", " ")
        inputline = inputline.Replace("¾", " ")
        inputline = inputline.Replace("¿", " ")
        inputline = inputline.Replace("Æ", " ")
        inputline = inputline.Replace("Ç", " ")
        inputline = inputline.Replace("Ð", " ")
        inputline = inputline.Replace("×", " ")
        inputline = inputline.Replace("Ø", " ")
        inputline = inputline.Replace("Ý", "Y")
        inputline = inputline.Replace("Þ", " ")
        inputline = inputline.Replace("ß", " ")
        inputline = inputline.Replace("æ", " ")
        inputline = inputline.Replace("ç", " ")
        inputline = inputline.Replace("ð", " ")
        inputline = inputline.Replace("÷", " ")
        inputline = inputline.Replace("ø", " ")
        inputline = inputline.Replace("ý", "y")
        inputline = inputline.Replace("þ", " ")
        inputline = inputline.Replace("ÿ", "y")

        Return inputline
    End Function

    ''' <summary>
    ''' Genera una nueva linea en el Archivo Log con los valores entregados
    ''' </summary>
    ''' <param name="strProceso">Nombre del proceso desde el cual es invocado</param>
    ''' <param name="strMensaje">Mensaje a Guardar</param>
    ''' <remarks></remarks>
    Public Shared Sub LoguearMensaje(ByVal strProceso As String, ByVal strMensaje As String)
        Dim rutaLog As String = System.Configuration.ConfigurationManager.AppSettings.Get("RutaLog")
        Dim Archivo As String = rutaLog & IIf(Left(rutaLog, 1) = "\", "", "\") & "Error_" & System.DateTime.Now.ToString("yyyyMMdd") & ".txt"
        Dim objLog As New clsGrabarLog()
        Try
            With objLog
                .RutaLog = Archivo
                .Impersonalizar = False
                .GrabarLog(strProceso, strMensaje)
            End With
        Catch SubEx As Exception
        Finally
            objLog.Dispose()
            objLog = Nothing
        End Try
    End Sub
End Class
